package cn.wolfcode.cms.service.impl;

import cn.wolfcode.cms.domain.SystemMenu;
import cn.wolfcode.cms.mapper.SystemMenuMapper;
import cn.wolfcode.cms.query.QueryObject;
import cn.wolfcode.cms.service.ISystemMenuService;
import cn.wolfcode.cms.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemMenuServiceImpl implements ISystemMenuService {

    @Autowired
    private SystemMenuMapper systemMenuMapper;

    public void delete(Long id) {
        if (id != null) {
            systemMenuMapper.deleteByPrimaryKey(id);
        }
    }

    public void save(SystemMenu systemMenu) {
        //添加菜单



        systemMenuMapper.insert(systemMenu);
    }


    public void update(SystemMenu systemMenu) {
        systemMenuMapper.updateByPrimaryKey(systemMenu);


    }

    public SystemMenu selectByPrimaryKey(Long id) {
        return systemMenuMapper.selectByPrimaryKey(id);
    }

    public List<SystemMenu> selectAll() {
        return systemMenuMapper.selectAll();
    }

    public PageResult query(QueryObject qo) {
        int total = systemMenuMapper.queryForCount(qo);
        if (total == 0) {
            return new PageResult();
        }
        List<SystemMenu> rows = systemMenuMapper.queryForList(qo);
        return new PageResult(total, rows);
    }


    public List<SystemMenu> getParentMenus() {
        return systemMenuMapper.getParentMenus();
    }

    public List<SystemMenu> listRoot() {
        return systemMenuMapper.listRoot();
    }

}
